﻿using Bouyei.GeoCore.Converters;
using Bouyei.GeoCore.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.GeoCore.GeoParsers.GeoJson
{
    public class GeoJsonGeometry
    {
        public string type { get; set; }

        [System.Text.Json.Serialization.JsonIgnore]
        public Geometry Geometry { get; protected set; }

        [System.Text.Json.Serialization.JsonIgnore]
        public GeoType GeometryType
        {
            get
            {
                switch (type.ToLower())
                {
                    case "point":
                        return GeoType.POINT;
                    case "multipoint":
                        return GeoType.MULTIPOINT;
                    case "linestring":
                        return GeoType.LINESTRING;
                    case "multilinestring":
                        return GeoType.MULTILINESTRING;
                    case "polygon":
                        return GeoType.POLYGON;
                    case "multipolygon":
                        return GeoType.MULTIPOLYGON;
                    case "geometrycollection":
                        return GeoType.GEOMETRYCOLLECTION;
                    default:
                        return GeoType.UNKNOWN;
                }
            }
        }

        protected JsonExtensions jsonConvert;

        public string getType()
        {
            switch (Geometry.GeometryType)
            {
                case GeoType.POINT:
                case GeoType.POINTZ:
                    return "Point";
                case GeoType.MULTIPOINT:
                    return "MultiPoint";
                case GeoType.LINESTRING:
                case GeoType.LINESTRINGZ:
                    return "LineString";
                case GeoType.MULTILINESTRING:
                    return "MultiLineString";
                case GeoType.POLYGON:
                case GeoType.POLYGONZ:
                    return "Polygon";
                case GeoType.MULTIPOLYGON:
                    return "MultiPolygon";
                default:
                    return Geometry.GeometryType.ToString();
            }
        }

        public GeoJsonGeometry()
        {
            jsonConvert = new JsonExtensions();
        }
    }
}
